<template>
	<view class="test-demo">
		<uni-group title="测试分组" >
        <button id="scanCode" class="btn btn-red" type="default" @click="toScan()">扫码</button>
        <button id="link" class="btn btn-red" type="primary" @click="toPage()">跳转</button>
        <button id="openDocument" class="btn btn-red" type="primary" >打开文档</button>
        <button id="downloadFile" class="btn btn-red" type="primary" >下载文档</button>
        <button id="chooseImage" class="btn btn-red" type="primary" @click="chooseImage()" >拍照或者选照片</button>
        <button id="chooseImage" class="btn btn-red" type="primary" @click="chooseVideo()" >拍视频</button>
        <button id="chooseImage" class="btn btn-red" type="primary" @click="chooseMedia()" >选照片视频</button>
        <button id="other" class="btn btn-red" type="primary" @click="callPhone()">拨打电话</button>
        <button id="layout" class="btn btn-red" type="warn" @click="layout()">退出</button>
        <button id="validToken" class="btn btn-red" type="primary" >验证token</button>
		</uni-group>

    <view id="mapDiv" style="height:100%;width: 100%;position:absolute;"></view>
	</view>
</template>

<script>
import UniGroup from "../../../uni_modules/uni-group/components/uni-group/uni-group.vue";

export default {
    components: {UniGroup},
	data() {
		return {
			map: {},
			label: '',
			zoom:14,
			localsearch: '',
			marker: {},

			timer:  '', // 防抖定时器
			pointAddress:{},
			centerPoint: {},
			gisPoints: [],
		}
	},
	onLaunch: function() {
		console.log('test demo Launch');

		this.pointAddress = new GisPoint();
		this.centerPoint = new GisPoint({Lng: 104.069777, Lat: 30.586055});
		var T = window.T;
		this.map = new T.Map("mapDiv");
		//设置显示地图的中心点和级别
		this.map.centerAndZoom(new T.LngLat(104.069777, 30.586055), this.zoom);
		// 设置地图缩放级别区间
		this.map.setMinZoom(5);
		this.map.setMaxZoom(18);

		let getMapDiv = setInterval(() => {
			let mapDiv = document.getElementById('mapDiv')
			if (mapDiv) {
				this.onLoad()
				clearInterval(getMapDiv)
			}
		}, 1000)
	},
	onShow: function() {
		console.log('test demo Show', this.$setting.INTERFACE_URL);

	},
	onHide: function() {
		console.log('test demo Hide')
	},
	methods: {
		toScan() {
			console.log("toScan,,,,")
			uni.$webViewUtil.postMessage({
				scan: true
			});
		},
		chooseImage(){
			uni.$webViewUtil.postMessage({
				chooseImage: {
					name: 'test',
					count: 1,
					sourceType: ['camera', 'album'],
					uploadUrl:"http://10.1.2.121:8006/smzApp/api/AccessoryMgeSvr.assx/add"
				}
			});
		},
		chooseVideo(){
			uni.$webViewUtil.postMessage({
				chooseVideo: {
					name: 'test',
					count: 1,
					sourceType: ['camera', 'album'],
					uploadUrl:"http://10.1.2.121:8006/smzApp/api/AccessoryMgeSvr.assx/add"
				}
			});
		},
		chooseMedia(){
			uni.$webViewUtil.postMessage({
				chooseMedia: {
					name: 'test',
					count: 1,
					sourceType: ['camera', 'album'],
					uploadUrl:"http://10.1.2.121:8006/smzApp/api/AccessoryMgeSvr.assx/add"
				}
			});
		},

		layout(){
			console.log("index.toScan.退出了")
			uni.$webViewUtil.postMessage({
				layout: true
			});
		},
		callPhone() {
			const phone = 13699420953
			console.log("拨打电话了："+phone)
			uni.$webViewUtil.makePhoneCall(phone)
		},
		getLocation(){
			console.log("index.getLocation....")
			uni.$webViewUtil.postMessage({
				getLocation: {
					type:'wgs84'
				}
			});

		},

		toPage(){
			console.log("index.toPage.")
			const url = setting.FJCY_WEBURL+"/#/pages/home/scheduInfo/index";
			uni.$webViewUtil.goToPage("navigateTo", url,'',1,'值班情况');
			console.log("index.toPage."+url)
		},
		onLoad() {
		    // _this = this;
		    //初始化地图对象
		    this.map = new T.Map("mapDiv");
		    //设置显示地图的中心点和级别
		    this.map.centerAndZoom(new T.LngLat(this.centerPoint.Lng, this.centerPoint.Lat), this.zoom);
		    // 设置地图缩放级别区间
		    this.map.setMinZoom(5);
		    this.map.setMaxZoom(18);
		    //允许鼠标滚轮缩放地图
		    // if (!this.isLooke){
				// 监听地图点击事件
				// this.map.addEventListener('click', this.onMapClick.bind(this));
		    // }
		    let config = {
		      pageCapacity: 10,	//每页显示的数量
		      onSearchComplete: this.localSearchResult	//接收数据的回调函数
		    };
		    //创建搜索对象
		    // this.localsearch = new T.LocalSearch(this.map, config);
		    // 加载标注点
		    // this.gisPoints.forEach((item:any) => {
		    //   this.addAddress(item)
		    // });
		  },

	}
}
</script>

<style scoped lang="less">

</style>
